package com.biodiv.miracle.web.adapter;

import com.biodiv.miracle.web.handler.DefaultHandler;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: tianquan
 * @date: 2025-05-27  13:53
 * @description: 默认的处理器适配器
 */
public class DefaultHandlerAdapter extends AbstractHandlerMethodAdapter {

    @Override
    public boolean supports(Object bean) {
        return bean instanceof Servlet;
    }

    @Override
    public Object handle(HttpServletRequest httpServletRequest, HttpServletResponse var2, Object handler) {
        if (handler instanceof DefaultHandler defaultHandler){
            try {
                defaultHandler.service(httpServletRequest, var2);
            } catch (ServletException e) {
                throw new RuntimeException(e);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return null;
    }

}
